import Vue from 'vue'
import App from './App.vue'
import router from './router/index'
// import './plugins/element.js'
import axios from 'axios'
import './assets/fonts/iconfont.css'
import './assets/css/globle.css'
// 导入树形组件
import tree from 'vue-table-with-tree-grid'
//导入富文本编辑器
// import VueQuillEditor from 'vue-quill-editor'
// import 'quill/dist/quill.core.css' // import styles
// import 'quill/dist/quill.snow.css' // for snow theme
// import 'quill/dist/quill.bubble.css' // for bubble theme
// 导入nprogress数据条
// import NProgress from 'nprogress'
// import '../node_modules/nprogress/nprogress.css'

// 在请求头中挂载token令牌
axios.interceptors.request.use(
    config => {
        //开始线条
        NProgress.start()
        config.headers.Authorization = sessionStorage.getItem('token')
        return config
    },
    err => {
        return Promise.reject(err)
    }
)
axios.interceptors.response.use(
        config => {
            //加结束线条
            NProgress.done()

            return config
        },
        err => {
            return Promise.reject(err)
        }
    )
    //配置基地址
axios.defaults.baseURL = 'http://118.190.160.53:8089/api/private/v1/'
    //在vue原型对象上挂载axios
Vue.prototype.$http = axios
    // 面板不提示
Vue.config.productionTip = false
    // 注册tree组件
Vue.component('TreeTable', tree)
    // 注册富文本编辑器
Vue.use(VueQuillEditor /* { default global options } */ )
    // 定义全局过滤器
Vue.filter('date', (val, a) => {
    function dateFormat(date, format) {
        if (typeof date === 'string') {
            var mts = date.match(/(\/Date\((\d+)\)\/)/)
            if (mts && mts.length >= 3) {
                date = parseInt(mts[2])
            }
        }
        date = new Date(date)
        if (!date || date.toUTCString() == 'Invalid Date') {
            return ''
        }
        var map = {
            M: date.getMonth() + 1, //月份
            d: date.getDate(), //日
            h: date.getHours(), //小时
            m: date.getMinutes(), //分
            s: date.getSeconds(), //秒
            q: Math.floor((date.getMonth() + 3) / 3), //季度
            S: date.getMilliseconds() //毫秒
        }

        format = format.replace(/([yMdhmsqS])+/g, function(all, t) {
            var v = map[t]
            if (v !== undefined) {
                if (all.length > 1) {
                    v = '0' + v
                    v = v.substr(v.length - 2)
                }
                return v
            } else if (t === 'y') {
                return (date.getFullYear() + '').substr(4 - all.length)
            }
            return all
        })
        return format
    }
    return dateFormat(val, a)
})

new Vue({
    router,
    render: h => h(App)
}).$mount('#app')